﻿using System;
using System.Collections.Generic;
using System.Text;
using VietKinsNutrition.Data;
using System.Data;
using System.Windows.Forms;

namespace VietKinsNutrition.Bussiness
{
    public class ClsTblDiemdanhtreanBLL : ClsBindingBLL
    {
        ClsTblDm_NamhocBLL ClsTblDm_Namhocbll = new ClsTblDm_NamhocBLL();
        public DataTable TblTredihoctrongthang(int LophocId, int ThanghocId)
        {
            DataTable Tbl = new DataTable();
            ClsTblDiemdanhtreanDAL ClsTblDiemdanhtreandalAcc = new ClsTblDiemdanhtreanDAL();
            Tbl = ClsTblDiemdanhtreandalAcc.TblSongaydihoccuatretrongthang(ClsTblDm_Namhocbll.ReturnNamhocId(), LophocId, ThanghocId);
            return Tbl;
        }
        public void Bind_LophocId(ComboBox Cbo, int NamhocID)
        {
            ClsTblTreBLL ClsTblTrebll = new ClsTblTreBLL();
            ClsTblTrebll.Bind_LophocCbo(Cbo, NamhocID);
        }
        public void Binddihoc_LophocId(ComboBox Cbo, int NamhocID)
        {
            ClsTblTreBLL ClsTblTrebll = new ClsTblTreBLL();
            ClsTblTrebll.Bind_LophocCbo(Cbo, NamhocID);
            try
            {
                ((DataTable)Cbo.DataSource).Rows.RemoveAt(0);
            }
            catch { }
        }
        ClsTblDiemdanhtreanDAL ClsTblDiemdanhtreandal = new ClsTblDiemdanhtreanDAL();
        public DataSet ReturnDiemdanhtrean()
        {
            return ClsTblDiemdanhtreandal.ReturnDiemdanhtrean();
        }

        //public DataSet SelectTblTienanthuctetrongthang(int NamhocId, int LophocId, int ThanghocId)
        //{
        //    ClsTblNamtrehocDAL ClsTblNamtrehocdal = new ClsTblNamtrehocDAL();
        //    DataSet Set0 = ClsTblDiemdanhtreandal.SelectTblTienanthuctetrongthang(NamhocId, LophocId, ThanghocId, -1);
        //    DataSet DsDsTre = new DataSet();
        //    DataTable Tbl = new DataTable();
        //    DsDsTre = (DataSet)((BindingSource)ClsTblNamtrehocdal.SelectAll(NamhocId, LophocId)).DataSource;
        //    DataSet ReturnSet = new DataSet();
        //    ReturnSet.Tables.Add(Tbl);
        //    ReturnSet.Tables[0].Columns.Add("STT", DsDsTre.Tables[0].Columns["STT"].DataType);
        //    ReturnSet.Tables[0].Columns.Add("NamtrehocId", Set0.Tables[0].Columns["NamtrehocId"].DataType);
        //    ReturnSet.Tables[0].Columns.Add("Hovaten", DsDsTre.Tables[0].Columns["Hovaten"].DataType);
        //    ReturnSet.Tables[0].Columns.Add("Tenthuonggoi", DsDsTre.Tables[0].Columns["Tenthuonggoi"].DataType);
        //    ReturnSet.Tables[0].Columns.Add("Tienanthang", Set0.Tables[0].Columns["Tienanthang"].DataType);
        //    int i = 0;
        //    foreach (DataRow Rw in DsDsTre.Tables[0].Rows)
        //    {
        //        // them row
        //        i = i + 1;
        //        ReturnSet.Tables[0].Rows.Add(i, Rw["Id"], Rw["Hovaten"], Rw["Tenthuonggoi"], 0);
        //    }
        //    foreach (DataRow Rw in ReturnSet.Tables[0].Rows)
        //    {
        //        double Tongtien = 0;
        //        string iNamtrehocId = "";
        //        Set0 = ClsTblDiemdanhtreandal.SelectTblTienanthuctetrongthang(NamhocId, LophocId, ThanghocId, int.Parse(Rw["NamtrehocId"].ToString()));
        //        foreach (DataRow Rw_ in Set0.Tables[0].Rows)
        //        {
        //            iNamtrehocId = Rw_["NamtrehocId"].ToString();
        //            Tongtien = Tongtien + double.Parse(Rw_["Tienanthang"].ToString());
        //        }
        //        if (Rw["NamtrehocId"].ToString().Trim() == iNamtrehocId)
        //        {
        //            Rw["Tienanthang"] = Tongtien.ToString();
        //        }
        //    }
        //    return ReturnSet;
        //}

        //public DataSet SelectTblTienanthuctetrongngay(int NamhocId, int LophocId, DateTime Ngaydiemdanh)
        //{
        //    //ClsTblNamtrehocDAL ClsTblNamtrehocdal = new ClsTblNamtrehocDAL();
        //    DataSet Set0 = ClsTblDiemdanhtreandal.SelectTblTienanthuctetrongngay(NamhocId, LophocId, Ngaydiemdanh, -1);
        //    DataSet DsDsTre = new DataSet();
        //    DataTable Tbl = new DataTable();
        //    DsDsTre = (DataSet)((BindingSource)ClsTblNamtrehocdal.SelectAll(NamhocId, LophocId)).DataSource;
        //    DataSet ReturnSet = new DataSet();
        //    ReturnSet.Tables.Add(Tbl);
        //    ReturnSet.Tables[0].Columns.Add("STT", DsDsTre.Tables[0].Columns["STT"].DataType);
        //    ReturnSet.Tables[0].Columns.Add("NamtrehocId", Set0.Tables[0].Columns["NamtrehocId"].DataType);
        //    ReturnSet.Tables[0].Columns.Add("Hovaten", DsDsTre.Tables[0].Columns["Hovaten"].DataType);
        //    ReturnSet.Tables[0].Columns.Add("Tenthuonggoi", DsDsTre.Tables[0].Columns["Tenthuonggoi"].DataType);
        //    ReturnSet.Tables[0].Columns.Add("Ngay", DsDsTre.Tables[0].Columns["Ngaysinh"].DataType);
        //    ReturnSet.Tables[0].Columns.Add("Tienanngay", Set0.Tables[0].Columns["Tienanngay"].DataType);
        //    int i = 0;
        //    foreach (DataRow Rw in DsDsTre.Tables[0].Rows)
        //    {
        //        // them row
        //        i = i + 1;
        //        ReturnSet.Tables[0].Rows.Add(i, Rw["Id"], Rw["Hovaten"], Rw["Tenthuonggoi"], Rw["Ngaysinh"], 0);
        //    }
        //    foreach (DataRow Rw in ReturnSet.Tables[0].Rows)
        //    {
        //        double Tongtien = 0;
        //        string iNamtrehocId = "";
        //        Set0 = ClsTblDiemdanhtreandal.SelectTblTienanthuctetrongngay(NamhocId, LophocId, Ngaydiemdanh, int.Parse(Rw["NamtrehocId"].ToString()));
        //        foreach (DataRow Rw_ in Set0.Tables[0].Rows)
        //        {
        //            iNamtrehocId = Rw_["NamtrehocId"].ToString();
        //            Tongtien = Tongtien + double.Parse(Rw_["Tienanngay"].ToString());
        //        }
        //        if (Rw["NamtrehocId"].ToString().Trim() == iNamtrehocId)
        //        {
        //            Rw["Tienanngay"] = Tongtien.ToString();
        //        }
        //    }
        //    return ReturnSet;
        //}

        public DataSet SelectTblTienanchotre(int NamhocId, int LophocId, DateTime Ngaydiemdanh)
        {
            return ClsTblDiemdanhtreandal.SelectTblTienanchotre(NamhocId, LophocId, Ngaydiemdanh);
        }
        //
        public DataSet SelectTblDiemdanhtredihoc(int LophocId, int ThanghocId, DateTime Ngaydiemdanh, int NamhocID)
        {
            ClsTblDm_NamhocBLL ClsTblDm_Namhocbll = new ClsTblDm_NamhocBLL();
            ClsTblDiemdanhtreanDAL ClsTblDiemdanhtreandalAcc = new ClsTblDiemdanhtreanDAL();
            return ClsTblDiemdanhtreandalAcc.SelectTblDiemdanhtredihoc(NamhocID, LophocId, ThanghocId, Ngaydiemdanh);
        }
        public DataTable TblDsTreMoi(int lophocId, int IdNamhocMoi)
        {
            DataTable Tbl = new DataTable();
            ClsTblDiemdanhtreanDAL ClsTblDiemdanhtreandalAcc = new ClsTblDiemdanhtreanDAL();
            Tbl = ClsTblDiemdanhtreandalAcc.TblDsTreMoi(lophocId, IdNamhocMoi);
            return Tbl;
        }
        public DataTable TblDsTre(int lophocId, int IdNamhocMOi)
        {
            DataTable Tbl = new DataTable();
            ClsTblDiemdanhtreanDAL ClsTblDiemdanhtreandalAcc = new ClsTblDiemdanhtreanDAL();
            Tbl = ClsTblDiemdanhtreandalAcc.TblDsTre(lophocId, IdNamhocMOi);
            return Tbl;
        }
        public DataSet SelectTblLenloptredihoc(int LophocId, int ThanghocId, DateTime Ngaydiemdanh, int NamhocID)
        {
            ClsTblDm_NamhocBLL ClsTblDm_Namhocbll = new ClsTblDm_NamhocBLL();
            ClsTblDiemdanhtreanDAL ClsTblDiemdanhtreandalAcc = new ClsTblDiemdanhtreanDAL();
            return ClsTblDiemdanhtreandalAcc.SelectTblLenloptredihoc(NamhocID, LophocId, ThanghocId, Ngaydiemdanh);
        }

        public DataSet SelectTblDiemdanhtrean(int LophocId, int ThanghocId, DateTime Ngaydiemdanh, int NamhocID)
        {
            ClsTblDm_NamhocBLL ClsTblDm_Namhocbll = new ClsTblDm_NamhocBLL();
            ClsTblDiemdanhtreanDAL ClsTblDiemdanhtreandalacc = new ClsTblDiemdanhtreanDAL();
            return ClsTblDiemdanhtreandalacc.SelectTblDiemdanhtrean(NamhocID, LophocId, ThanghocId, Ngaydiemdanh);
        }
        public void Insert(int NamtrehocId, int ThanghocId, DateTime Ngay, Boolean Tinhtrang)
        {
            ClsTblDiemdanhtreanDAL ClsTblDiemdanhtreandalacc = new ClsTblDiemdanhtreanDAL();
            ClsTblDiemdanhtreandalacc.Insert(NamtrehocId, ThanghocId, Ngay, Tinhtrang);
        }
        public void Insert_Tredihoc(int NamtrehocId, int ThanghocId, DateTime Ngay, Boolean Tinhtrang)
        {
            ClsTblDiemdanhtreanDAL ClsTblDiemdanhtreandalAcc = new ClsTblDiemdanhtreanDAL();
            ClsTblDiemdanhtreandalAcc.Insert_Tredihoc(NamtrehocId, ThanghocId, Ngay, Tinhtrang);
        }

        public void Edit(int Id, int NamtrehocId, int ThanghocId, DateTime Ngay, Boolean Tinhtrang)
        {
            ClsTblDiemdanhtreanDAL ClsTblDiemdanhtreandalAcc = new ClsTblDiemdanhtreanDAL();
            ClsTblDiemdanhtreandalAcc.Edit(Id, NamtrehocId, ThanghocId, Ngay, Tinhtrang);
        }
        public void Edit_Tredihoc(int Id, int NamtrehocId, int ThanghocId, DateTime Ngay, Boolean Tinhtrang)
        {

            ClsTblDiemdanhtreanDAL ClsTblDiemdanhtreandalAcc = new ClsTblDiemdanhtreanDAL();
            ClsTblDiemdanhtreandalAcc.Edit_Tredihoc(Id, Tinhtrang);
        }
        public void Bind_BuaanCbo(ComboBox Cbo)
        {
            ClsTblDm_BuaantrongngayDAL ClsTblDm_Buaantrongngaydal = new ClsTblDm_BuaantrongngayDAL();
            Cbo.DataSource = ClsTblDm_Buaantrongngaydal.SelectAll();
            Cbo.ValueMember = "Id";
            Cbo.DisplayMember = "Tenbuaan";
        }
        //public void UpdateTienan(int Id, float Tienan)
        //{
        //    this.ClsTblDiemdanhtreandal.UpdateTienan(Id, Tienan);
        //}

    }
}
